import Vue from "vue";
import Router from "vue-router";
import Home from "../views/index.vue";
import venue from "../views/venue";
import guest from "../views/guest";
import city from "../views/city";
import about from "../views/about";
import RESEVATION from "../views/reservation";
import BANQUET from "../views/banquet";
import PROMOTIONE from "../views/promotion";
Vue.use(Router);
const router = new Router({
  mode: "history",
  routes: [
    {
      path: "/",
      redirect: "/index",
    },
    {
      path: "/index", //链接路径
      component: Home, //对应的组件模板
    },
    {
      path: "/venue",
      component: venue,
    },
    {
      path: "/guest",
      component: guest,
    },
    {
      path: "/city",
      component: city,
    },
    {
      path: "/about",
      component: about,
    },
    {
      path: "/reservation",
      component: RESEVATION,
    },
    {
      path: "/banquet",
      component: BANQUET,
    },
    {
      path: "/promotion",
      component: PROMOTIONE,
    },
  ],
});
// 解决重复点击导航时，控制台出现报错
const VueRouterPush = Router.prototype.push;
Router.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch((err) => err);
};
router.beforeEach((to, from, next) => {
  console.log(to, "--to--");
  console.log(from, "--from--");

  if (to.path === from.path) {
    return false;
  } else {
    next();
  }
  // 返回 false 以取消导航
});
export default router;
